<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue.set 全局操作</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
    <h1>vue.set 全局操作</h1>
    <hr>
    <div id="app">
        {{count}}        
        <ul>
            <li v-for="item in arr">{{item}}</li>
        </ul>
    </div>

    <p>
        <button onclick="add();">add</button>
    </p>

    <script type="text/javascript">
        function add(){
            //Vue 方法,可以将对象下面的属性直接set = value
            // Vue.set(outData,'count',2);

            //对象属性
            //app.count++;

            //原生方法
            //outData.count++;

            //改变数组的值 ,Vue没法监听到下标,改变数组的长度都是无法监听到
            app.arr[1]='ddd';

            //使用Vue提供的set方法可以改变数组的值 .
            Vue.set(app.arr,1,'eee');
        }



        //外部对象
        var outData={
            count : 1,
            // goods:'car'
            arr : ['aaa','bbb','ccc']
        };

        var app = new Vue({
            el:'#app',
            //调用外部对象
            data:outData
        })
    </script>
</body>
</html>